package autotrade.asp;

import java.io.IOException;
import java.util.Calendar;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import autotrade.data.PMF;
import autotrade.data.structure.FxDatum;

@SuppressWarnings("serial")
public class RemoveRateServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
	throws IOException {
		Calendar now = Calendar.getInstance();
		now.add(Calendar.DATE, -2);
		now.set(Calendar.HOUR, 0);
		now.set(Calendar.MINUTE, 0);
		now.set(Calendar.SECOND, 0);
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		
		Query query = pm.newQuery(FxDatum.class);
		
		@SuppressWarnings("unchecked")
		List<FxDatum> list = (List<FxDatum>)query.execute();
		resp.getWriter().print(list.size());
		pm.deletePersistentAll(list);
	}
}
